package com.cj.service.impl;

import com.cj.dao.DormcleanDao;
import com.cj.po.*;
import com.cj.service.DormcleanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service("DormcleanService")
@Transactional
public class DormcleanServiceImpl  implements DormcleanService {
   //注入dao
   @Autowired
   private DormcleanDao dormcleanDao;
    //分页查询
    @Override
    public PageInfo<Dormclean> findPageInfo(Integer d_id,String d_dormbuilding,
                                            Integer pageIndex, Integer pageSize) {
        PageInfo<Dormclean> di = new PageInfo<Dormclean>();
        di.setPageIndex(pageIndex);
        di.setPageSize(pageSize);


        //获取总条数
        Integer totalCount = dormcleanDao.totalCount(d_id,d_dormbuilding);
        if (totalCount>0){
            di.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormclean> dormcleanList = dormcleanDao.getDormcleanList(d_id,d_dormbuilding,
                    (di.getPageIndex()-1)*di.getPageSize(),di.getPageSize());
          di.setList(dormcleanList);
        }
        return di;

    }

    @Override
    public List<Dormclean> getAll() {
        List<Dormclean> dormcleanList = dormcleanDao.getAll();
        return dormcleanList;
    }


    @Override
    public int deleteDormclean(Integer d_id) {
        return dormcleanDao.deleteDormclean(d_id);
    }

    @Override
    public int addDormclean(Dormclean dormclean) {
        dormclean.setCreate_time(new Date());
        dormclean.setUpdate_time(new Date());
        return dormcleanDao.addDormclean(dormclean);
    }

    @Override
    public int updateDormclean(Dormclean dormclean) {
        return dormcleanDao.updateDormclean(dormclean);
    }

    @Override
    public Dormclean findDormCleanById(Integer d_id) {
        return dormcleanDao.findDormCleanById(d_id);
    }

}
